<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
    var Temp= function () {
        this.year=function(){
            var list=[],month;
            for(var i=12;i;i--){
                month=[[1,2,3,4,5,6,7],[8,9,10,11,12,13,14],[15,16,17,18,19,20,21],[22,23,24,25,26,27,28]];
                list.push(month);
            }
            return list;
        }();
        this.averageMonth= function (monthIdx) {
            var month=this.year[monthIdx],sum= 0,week;
            //console.log('month:',month);
            for(var i=0;i<month.length;i++){
                week=month[i];
                //console.log('week:',week);
                for(var j=0;j<week.length;j++){
                    sum+=week[j];
                }
            }
            return sum/12;
        }
        this.averageWeek= function (monthIdx, weekIdx) {
            var week=this.year[monthIdx][weekIdx],sum=0;
            for(var i=0;i<week.length;i++){
                sum+=week[i];
            }
            return sum/7;
        }
        this.averageWeeks= function () {
            var sum= 0,month,week;
            for(var i=0;i<this.year.length;i++){
                month=this.year[i];
                for(var j=0;j<month.length;j++){
                    week=month[j];
                    for(var k=0;k<week.length;k++){
                        sum+=week[k];
                    }
                }
            }
            return sum/48;
        }
    }

    var t1=new Temp();
    console.log(t1);
    console.log(t1.averageMonth(0));
    console.log(t1.averageWeek(0,0));
    console.log(t1.averageWeeks());
</script>
</body>
</html>